package com.xinchuang.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xinchuang.comment.R;
import com.xinchuang.service.CronService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 定时相关
 */
@RestController
@RequestMapping(value = "/cron")
@RequiredArgsConstructor
@Api(value = "定时接口", tags = "定时接口")
public class CronController {

    private final CronService cronService;

    @PostMapping("/cronList")
    @ApiOperation("定时列表")
    public R cronList() {
        return JSON.parseObject(cronService.cronList(), R.class);
    }

    @ApiOperation("添加定时")
    @PostMapping(value = "/addCron")
    public R addCron(@RequestBody JSONObject jsonObject) {
        return JSON.parseObject(cronService.addCron(jsonObject), R.class);
    }

    @ApiOperation("编辑定时")
    @PostMapping(value = "/editCron")
    public R editCron(@RequestBody JSONObject jsonObject) {
        return JSON.parseObject(cronService.editCron(jsonObject), R.class);
    }


}
